﻿using CatUtils.Utils.Currency;
using CatUtils.Utils.Currency.TextUtils;

using CatUtils.Utils.SpecialUtils.Html;
using CatUtilsDll.Utils.Currency.WebUtils;
using RabbitDownload.Helper.Currency;

using System;
using System.Collections.Generic;

namespace RabbitDownload.WebSite.Bcy.Search
{
    internal class ScannerBcySearch
    {
        public static void Start(String Tag)
        {
            if (Tag == "")
                return;

            String SearchUrl = string.Format("https://bcy.net/search/home?k={0}&p={1}",  WebHelper.UrlEncode(Tag), "{0}");
            List<string> AllArticleList = new List<string>();
            int PageCount = 1;
            while (true)
            {
                Console.WriteLine("正在解析第{0}页", PageCount);
                int flag = AllArticleList.Count;
                Console.WriteLine(AnalysisList(string.Format(SearchUrl, PageCount++)).Count);
                AllArticleList.AddRange(AnalysisList(string.Format(SearchUrl, PageCount++)));
                if (flag == AllArticleList.Count)
                {
                    Console.WriteLine("全部扫描完成,共有{0}篇文章待处理。", AllArticleList.Count);
                    BcyAnalysisContent.AutoDownlod(AllArticleList);
                    break;
                }
            }
        }

        private static List<string> AnalysisList(string SearchUrl)
        {
            Console.WriteLine(SearchUrl);
            String Shtml = WebHelper.HttpPcGet(SearchUrl);
            List<string> Templist = new List<string>();
            foreach (string line in HtmlHelper.GetLinkVlaueList(Shtml, "//li[@class='_box']/a"))
            {
                Templist.Add("https://bcy.net" + line);
            }
            return Templist;
        }
    }
}